package com.stars.module.log.service.impl;

import com.stars.module.log.entity.LogEntity;
import com.stars.module.log.entity.LogEnum;
import com.stars.module.log.mapper.LogMapper;
import com.stars.module.log.service.StarLogService;
import com.stars.util.common.DevelopKit;
import org.springframework.stereotype.Service;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2022/11/14 23:33
 * @description : 日志记录服务实现类
 */
@Service
public class StarLogServiceImpl implements StarLogService {

    private final LogMapper logMapper;

    public StarLogServiceImpl(LogMapper logMapper) {
        this.logMapper = logMapper;
    }

    @Override
    public boolean saveLog(LogEntity log) {
        return logMapper.insert(log) > 0;
    }

    @Override
    public boolean saveLog(LogEnum logEnum, String content) {

        LogEntity entity = new LogEntity();

        entity.setId(DevelopKit.generateUUID());
        entity.setContent(content);
        entity.setType(logEnum.type());
        entity.setTypeText(logEnum.text());

        DevelopKit.setBaseInfo(entity);

        return saveLog(entity);
    }
}
